import type { FormSchema } from '@/components/core/schema-form/';
import { InboxOutlined } from '@ant-design/icons-vue';
import { downloadAttament } from '@/api/workorder/common/attachment';
import { reactive } from 'vue';

// 当前页面使用的数据
export let uploadFileReplyObject = reactive({
  uploadFileList: [],
  defaultFileList: [],
});

export const workOrderReplyschemas: FormSchema[] = [
  
  {
    
    field: 'handledId',
    component: 'Input',    
    componentProps: {
      hidden: true,
    },
    colProps: {
      span: 0,
    },
  },
  {
    
    field: 'replyNo',
    component: 'Input',
    label: '回复单号',
    colProps: {
      span: 12,
    },
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'replyType',
    component: 'RadioGroup',
    label: '反馈方式',
    colProps: {
      span: 10,
    },
    rules: [{ required: true, type: 'string' }],
    defaultValue: '0',
    componentProps: {
      options: [
        {
          label: '回单',
          value: '0',
        },
        {
          label: '退单',
          value: '2',
        },
      ],
    },
  },
  {
    field: 'replyerId',
    component: 'Input',
    colProps: {
      span: 2,
    },
    componentProps: {
      hidden: true,
    },
  },
  {
    field: 'replyer',
    component: 'Input',
    label: '经',
    rules: [
      { required: true, type: 'string' },
    ],
    colProps: {
      span: 18,
    },
  },
  {
    field: 'divider-basic',
    component: 'Divider',
    label: '核查，',
    componentProps: {
      type: 'vertical',
    },
    colProps: {
      span: 6,
    },
  },
  {
    field: 'replyContent',
    component: 'InputTextArea',
    label: '',
    componentProps: {
      placeholder: '请输入回复内容',
      rows: 6
    },
   
    formItemProps: {
      colon: false,
    },
    rules: [
      { required: false, type: 'string' },
      { max: 1000, message: '回复内容不能超过500个字' },
    ],
    colProps: {
      span: 24,
    },
  },
  {
    field: 'handledBy',
    component: 'Input',
    label: '经办人',
    rules: [
      { required: false, type: 'string' },
      { max: 20, message: '回复内容不能超过10个字' },
    ],
    
    colProps: {
      span: 12,
    },
  },
  {
    field: 'contactNumber',
    component: 'Input',
    label: '联系电话',
    rules: [
      { required: false, type: 'string' },
      {
        required: false,
        type: 'string',
        validator: (_, value) => {
          let regPhone = /^[1][3,4,5,7,8][0-9]{9}$/;
          let regTel = /^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$/;
          const isError = !(regPhone.test(value) || regTel.test(value));
          if (value && isError) {
            return Promise.reject('请输入正确的手机号码或固话号码');
          } else {
            return Promise.resolve();
          }
        },
      },
      { max: 13, message: '联系电话不能大于13个字符' },
    ],
    colProps: {
      span: 12,
    },
  },
  {
    field: 'attament',
    component: 'UploadDragger',
    label: '附件',
    colProps: {
      span: 24,
    },
    componentProps: {
      beforeUpload: () => {
        return false;
      },
      onChange: (fileList: any) => {
        uploadFileReplyObject.uploadFileList = fileList.fileList;
      },
      showUploadList: {
        showDownloadIcon: true,
      },
      onDownload: (file) => {
        // 文件下载
        downloadAttament(file.uid);
      },
    },
    componentSlots: {
      default: () => (
        <div>
          <p>
            <InboxOutlined />
          </p>
          <p style={'color:blue'}>将文件拖到此处或点击上传</p>
        </div>
      ),
    },
  },
];
